<template>
  <div class="container">
    <div class="search">
      <el-row :gutter="20">
        <el-col :md="20" :xs="24">
          <el-input
            placeholder="请输入内容"
            v-model="searchData"
            type="textarea"
            autosize
            maxlength="128"
            @keyup.enter.native="search"
          >
          </el-input>
        </el-col>
        <el-col :md="4" :xs="24">
          <el-button type="primary" class="search_btn" @click="search"
            >搜索</el-button
          >
        </el-col>
      </el-row>
    </div>
    <div class="results" v-loading="loading">
      <result
        v-for="(result, index) in results"
        :key="index"
        :result="result"
      ></result>
    </div>
  </div>
</template>

<script>
import Result from "./Result.vue";
export default {
  components: { Result },
  data() {
    return {
      searchData: null,
      results: [],
      type: "选择题",
      maxNum: 2,
      loading: false,
    };
  },
  methods: {
    async search() {
      this.results = [];
      this.loading = true;
      const { data: res } = await this.$http.get("problem/es", {
        params: {
          title: this.searchData,
        }
      });
      this.loading = false;
      if (res.code == 200) {
        return this.$message.error("无结果");
      }
      this.results = res.data.problems;

    },
  },
};
</script>

<style lang="scss">
.container {
  min-height: 100%;
  overflow: hidden;
  .search {
    margin: 0 auto;
    margin-top: 30px;
  }
  .radios {
    margin: 0 auto;
    margin-top: 10px;
  }
  .results {
    margin: 0 auto;
    margin-top: 30px;
    margin-left: -60px;
  }
  @media screen and (max-width: 768px) {
    .search {
      width: 75%;
      text-align: center;
      .el-button {
        margin-top: 20px;
        width: 50%;
      }
    }
    .radios {
      text-align: center;
    }
  }
  @media screen and (min-width: 992px) {
    .search {
      width: 50%;
      .el-textarea {
        .el-textarea__inner {
          min-height: 40px !important;
          line-height: 2;
        }
      }
    }
    .radios {
      text-align: left;
      width: 50%;
    }
  }
}
</style>
